/*
 * reader_model_bookstore.h
 *
 *  Created on: 2010-03-04
 *      Author: alex
 */

#ifndef READER_MODEL_BOOKSTORE_H_
#define READER_MODEL_BOOKSTORE_H_

#include "addon_features.h"
#include "addon_std.h"
#include "addon_objbase.h"
#include "cx_xmlp.h"
#include "addon_llist.h"
#include "system_define.h"
#include "cx_escape_str.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum
{
	UPDATE_TYPE_UNKNOWN,
	UPDATE_TYPE_FORCIBLY,
	UPDATE_TYPE_SUGGESTION
		
}meta_update_type_e;

typedef enum
{
	PAGE_BOOK_UNKNOWN,
	PAGE_BOOK_INFO,
	PAGE_HOME_PAGE,
	PAGE_ACTUAL_URL,
	PAGE_SEARCH_FAIL,
	PAGE_DOWNLOAD_BOOK,
	PAGE_DOWNLOAD_CHAPTER,
	PAGE_DOWNLOAD_WHOLE_BOOK,
	PAGE_ONLINE_BOOK,
	PAGE_RECORD_BOOK,
	PAGE_UPDATE_PAGE,
	PAGE_SHOWRANDOMBOOKS_PAGE
}meta_page_type_e;

typedef enum
{
	FONT_UNKNOWN,
	FONT_BOLD,
	FONT_ITALIC
}text_font_e;

typedef enum
{
	PREFIX_UNKNOWN,
	PREFIX_POINT
}prefix_type_e;

typedef enum
{
	XML_BYTE_DATA,
	XML_FILE_DATA
}xml_data_type;

//typedef enum
//{
//	EXTRA_TAG_BEGIN,
//	EXTRA_BOOK,
//	EXTRA_CHAPTER,
//	EXTRA_CATALOG,
//	EXTRA_UPDATE,
//	EXTRA_PAGENO,
//	EXTRA_PAGETOTAL,
//	EXTRA_URL,
//	BODY_TAG_BEGIN,
//	BODY_A = BODY_TAG_BEGIN,
//	BODY_P,
//	BODY_TEXT,
//	BODY_DUALTEXT,
//	BODY_TRITEXT,
//	BODY_BUTTON,
//	XML_MENU,
//	XML_INPUTBOX,
//	XML_TAG_END = XML_INPUTBOX
//}xml_tag_type;

typedef enum
{
	ELEMENT_PAGE,
	ELEMENT_LINE,
	ELEMENT_TABLE,
	ELEMENT_COL,
	ELEMENT_MULTLINE,
	ELEMENT_A,
	ELEMENT_P,
	ELEMENT_I,
	ELEMENT_ACTIVE,
	ELEMENT_LOCALACTIVE,
	ELEMENT_BUTTON,
	ELEMENT_CONST,
	DATA_ELEMENT_URL,
	DATA_ELEMENT_BOOK,
	DATA_ELEMENT_CHAPTER,

	EXTRA_TAG_BEGIN,
	EXTRA_BOOK,
	EXTRA_CHAPTER,
	EXTRA_CATALOG,
	EXTRA_UPDATE,
	EXTRA_PAGENO,
	EXTRA_PAGETOTAL,
	EXTRA_URL,
	BODY_TAG_BEGIN,
	BODY_A = BODY_TAG_BEGIN,
	BODY_P,
	BODY_TEXT,
	BODY_DUALTEXT,
	BODY_TRITEXT,
	BODY_BUTTON,
	XML_MENU,
	XML_INPUTBOX,
	XML_TAG_END = XML_INPUTBOX
}xml_tag_type;


typedef struct  
{
	xmlp_string_ptr_t   key;
	xmlp_string_ptr_t   url;
}page_const_tag_t,*page_const_tag_ptr_t;

typedef struct 
{
	addon_llist_t		childtag_list;
}page_const_tag_list_t,*page_const_tag_list_ptr_t;

typedef enum
{
	page_active_onclick_none,
	page_active_onclick_search,
	page_active_onclick_jumppage
}page_onclick_style;

typedef enum
{
	page_focus_true,
	page_focus_false
}page_focus;

typedef struct 
{
	QDWORD              scale;
	QDWORD              width;
	QDWORD              left_margin;
	QDWORD 	            height;
	xmlp_string_ptr_t   style;
	xmlp_string_ptr_t   url;
	QDWORD 	            onclick;
	xmlp_string_ptr_t   alt_url;
	xmlp_string_ptr_t   content;
	page_focus          focus;
	QDWORD              padding;
}page_active_tag_t,*page_active_tag_ptr_t;

typedef enum
{
	page_localactive_id_history
}page_localactive_id;

typedef struct 
{
	QDWORD   id;
}page_localactive_tag_t,*page_localactive_tag_ptr_t;

typedef struct 
{
	QDWORD              scale;
	QDWORD              width;
	QDWORD              left_margin;
	xmlp_string_ptr_t   url;
	xmlp_string_ptr_t   content;
	page_focus          focus;
	QDWORD              padding;
}page_button_tag_t,*page_button_tag_ptr_t;

typedef struct 
{
	QDWORD 	            height;
	QDWORD              bgcolor;
	xmlp_string_ptr_t   style;
	addon_llist_t		childtag_list;
	page_focus          focus;
}page_line_tag_t,*page_line_tag_ptr_t;

typedef struct 
{
	QDWORD 	            scale;
	addon_llist_t		childtag_list;
}page_column_tag_t,*page_column_tag_ptr_t;

typedef struct 
{
	QDWORD 	            height;
	QDWORD 	            span;
	addon_llist_t		childtag_list;
}page_table_tag_t,*page_table_tag_ptr_t;

typedef struct 
{
	xmlp_string_ptr_t 	url;
	addon_llist_t		line_list;
	page_focus          focus;
}page_mutiline_tag_t,*page_mutiline_tag_ptr_t;


typedef enum
{
	page_p_style_text,
	page_p_style_title
}page_p_style;

typedef enum
{
	page_alien_left,
	page_alien_right,
	page_alien_middle
}page_alien;

typedef enum
{
	page_p_wrap_true,
	page_p_wrap_false
}page_p_wrap;

typedef struct  
{
	xmlp_string_ptr_t  style;
	QDWORD             alien;
	QDWORD             scale;
	QDWORD             left_margin;
	QDWORD             wrap;
	QDWORD             span;
	xmlp_string_ptr_t  content;
}page_p_tag_t,*page_p_tag_ptr_t;

typedef enum
{
	page_a_style_text,
	page_a_style_searchbar,
	page_a_style_pagebar
}page_a_style;

typedef struct  
{
	xmlp_string_ptr_t  style;
	QDWORD             alien;
	QDWORD             scale;
	QDWORD             left_margin;
	xmlp_string_ptr_t  url;
	xmlp_string_ptr_t  alt_url;
	xmlp_string_ptr_t  content;
	page_focus         focus;
	QDWORD             padding;
	QDWORD 	           width;
}page_a_tag_t,*page_a_tag_ptr_t;

typedef enum
{
	page_i_local_0,
	page_i_local_1
}page_i_local;

typedef struct  
{
	xmlp_string_ptr_t  style;
	xmlp_string_ptr_t  url;
	QDWORD 	           width;
	QDWORD 	           height;
	xmlp_string_ptr_t  local;
	QDWORD 	           left_margin;
}page_i_tag_t,*page_i_tag_ptr_t;

typedef struct 
{
	xmlp_string_ptr_t 	id;
	QDWORD 	max_chapter;
	xmlp_string_ptr_t book_title;
	xmlp_string_ptr_t book_info;
}meta_book_tag_t,*meta_book_tag_ptr_t;

typedef struct 
{
	xmlp_string_ptr_t url;
}meta_url_tag_t,*meta_url_tag_ptr_t;

typedef struct
{
	QDWORD id;

}meta_catalog_tag_t,*meta_catalog_tag_ptr_t;

typedef struct
{
	QDWORD id;
	xmlp_string_ptr_t chapter_title;
}meta_chapter_tag_t,*meta_chapter_tag_ptr_t;

typedef struct
{
	xmlp_string_ptr_t	url;
	xmlp_string_ptr_t	intro;
	xmlp_string_ptr_t   title;
	xmlp_string_ptr_t   version;
	unsigned int		seq;
	unsigned int        type;

}meta_update_tag_t,*meta_update_tag_ptr_t;

typedef struct  
{
	unsigned long page_num;
}meta_pageno_tag_t,*meta_pageno_tag_ptr_t;

typedef struct  
{
	unsigned long total;
}meta_pagetotal_tag_t,*meta_pagetotal_tag_ptr_t;

/********* meta and body all maybe have tags ************/
typedef struct  
{
	xmlp_string_ptr_t url;
	xmlp_string_ptr_t label;
	xmlp_string_ptr_t type;
	addon_llist_t menu_childtag_list;
}menu_tag_t,*menu_tag_ptr_t;

typedef struct  
{
	xmlp_string_ptr_t title;
	xmlp_string_ptr_t type;
	xmlp_string_ptr_t property;
	xmlp_string_ptr_t labe;

}inputbox_tag_t,*inputbox_tag_ptr_t;
/*******************************************************/

typedef struct  
{
	xmlp_string_ptr_t  user_id;
	meta_page_type_e page_type;
	addon_llist_t const_list;
	addon_llist_t extra_list;
	addon_llist_t menus_list;
}meta_tag_t,*meta_tag_ptr_t;

typedef struct
{
	unsigned long	color;
	text_font_e		font;	
	prefix_type_e	prefix_type;
}body_tag_style_t,*body_tag_style_ptr_t;

typedef struct
{
	xmlp_string_ptr_t	content;
	xmlp_string_ptr_t 	icon;
	xmlp_string_ptr_t   url;
	body_tag_style_t	style;
	addon_llist_t		text_childtag_list;
	
}body_text_tag_t,*body_text_tag_ptr_t;

typedef struct
{
	xmlp_string_ptr_t 	icon;
	xmlp_string_ptr_t 	title;
	xmlp_string_ptr_t 	content;
	body_tag_style_t	style;
	xmlp_string_ptr_t   url;
	addon_llist_t		dualtext_childtag_list;
}body_dualtext_tag_t,*body_dualtext_tag_ptr_t;

typedef struct
{
	xmlp_string_ptr_t 	info1;
	xmlp_string_ptr_t 	info2;
	xmlp_string_ptr_t 	info3;
	xmlp_string_ptr_t 	icon;
	body_tag_style_t	style;
	xmlp_string_ptr_t   url;
	addon_llist_t		tritext_childtag_list;
}body_tritext_tag_t,*body_tritext_tag_ptr_t;

typedef struct  
{
	xmlp_string_ptr_t   name;
	xmlp_string_ptr_t   url;
	body_tag_style_t	style;
	addon_llist_t		button_childtag_list;
}body_button_tag_t,*body_button_tag_ptr_t;

typedef struct  
{
	addon_llink_t	link;
	xml_tag_type	tag_type;
}xml_tag_header_t,*xml_tag_header_ptr_t;

typedef struct  
{
	addon_llist_t body_childtag_list;
}body_tag_t,*body_tag_ptr_t;

typedef struct  
{
	xmlp_string_ptr_t  image;
}xml_image_data_t,*xml_image_data_ptr_t;

typedef struct  
{
	QDWORD             page_id;
	addon_llist_t      image;
}xml_image_list_t,*xml_image_list_ptr_t;

typedef struct  
{
	xml_image_list_ptr_t image_list;
	meta_tag_ptr_t       meta_tag;
	body_tag_ptr_t       body_tag;
	xmlp_document_ptr_t  doc;
}xml_tag_data_t,*xml_tag_data_ptr_t;

void * xml_get_obj_data(unsigned long obj);

QBOOL qqr_xml_init(void);
void qqr_xml_deinit();

unsigned long Parse_xml_tag_data(void *data,int size,xml_data_type data_type);
unsigned long Start_parse_xml_tag_data(void *data,int size,xml_data_type data_type);

void xml_ucs2_to_utf8_string(unsigned char *dest,int dest_size,unsigned char * src);
//int convert_url_to_utf8(char ** pDst,unsigned short* pSrc);
//int copy_string_w(unsigned short ** pDst,unsigned short* pSrc);
unsigned long xmlp_utf8_to_ucs2_string( void * buff_ptr, unsigned long buff_size, void * utf8_str, unsigned long utf8_len );

void get_last_page_id(unsigned char ** id);
unsigned short* get_last_page_str();
unsigned short* get_last_user_str();
void set_last_user_str(unsigned short* userid);
void set_last_page_str(unsigned short* pageid);
#ifdef __cplusplus
}
#endif //extern "C"

#endif
